<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <div>获取验证码</div>
  <script>
    /*
    防抖和节流  编码一种技巧 


     */

    const div = document.querySelector("div");

    div.onclick = function () {
      // 用不了了！！！
      div.disabled = true;

      // 定义时间
      let time = 3;
      div.innerText = time + "秒后再获取";

      let timeid = setInterval(() => {
        time--;
        // 按钮修改文本
        div.innerText = time + "秒后再获取";

        if (time === -1) {
          clearInterval(timeid);
          div.disabled = false;
          div.innerText = "获取验证码";
        }
      }, 1000);

    }

  </script>
</body>

</html>